﻿
//
// Copyright (c) 2024 BPer
//
#ifndef INCLUDE_BPERUTIL_SYS_BPERSYSMESSAGEHANDLE_H_
#define INCLUDE_BPERUTIL_SYS_BPERSYSMESSAGEHANDLE_H_
#include <bperutil/sys/BPerSysMessageI.h>
#include <bperutil/sys/BPerThread2.h>
#include <vector>


using namespace std;

class BPerSysMessageHandle :public BPerThread{
public:
	BPerSysMessageHandle();
	virtual ~BPerSysMessageHandle();
	virtual void handleMessage(BPerSysMessage* mss)=0;
	virtual void initAll()=0;
	virtual void deleteAll()=0;
	void putMessage(BPerSysMessageI *handle,int32_t pst, int32_t puid, int32_t handleState,void* user=NULL);

	static BPerSysMessageHandle* m_instance;
	BPerBool m_isStart;
	BPerBool m_loop;
	void stop();
protected:
	void run();
	void startLoop();
	void stopLoop();

private:
	vector<BPerSysMessage*> m_sysMessages;
	bPer_thread_mutex_t m_mutex;
	bPer_thread_mutex_t m_lock;
	bPer_thread_cond_t m_cond_mess;

	BPerBool m_waitState;
	BPerSysMessageHandleI* m_receive;

};

#endif /* INCLUDE_BPERUTIL_SYS_BPERSYSMESSAGEHANDLE_H_ */
